package com.simon.annual.service.impl;

import javax.annotation.Resource;

import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.stereotype.Service;

import com.simon.annual.entity.ReportNeeq;
import com.simon.annual.repositoy.IReportNeeqRepositoy;
import com.simon.annual.service.ICompanyPublicInfo;

/**
 * 第九节:公司治理及内部控制
 * @author YXM
 * */
@Service
public class GovernanceImpl{
	@Resource
	private ICompanyPublicInfo cmpanyPublicInfo;
	@Resource
	private IReportNeeqRepositoy reportNeeqRepositoy;

	public void analysis(Element e, ReportNeeq reportNeeq, int companyPtrId) {
		//事项是或否
		Element governance = cmpanyPublicInfo.findNextTag("table",e);
		Elements governanceTd = governance.select("table tr > *");
		reportNeeq.setHasNewGovernancePolicy(governanceTd.get(3).text());
		reportNeeq.setHasProfessionalCommittee(governanceTd.get(5).text());
		reportNeeq.setHasIndependentDirector(governanceTd.get(7).text());
		reportNeeq.setHasInvestmentHouseDirector(governanceTd.get(9).text());
		reportNeeq.setHasSupervisorDisagreement(governanceTd.get(11).text());
		reportNeeq.setHasProfessionalManager(governanceTd.get(13).text());
		reportNeeq.setHasInternalControlSigFault(governanceTd.get(15).text());
		reportNeeq.setHasPolicyAgainstMajorReportError(governanceTd.get(17).text());
		//公司治理基本状况
		Element governanceReview = cmpanyPublicInfo.findNextTag("table",governance);
		reportNeeq.setGovernanceReview(governanceReview.text());
		//公司治理机制是否给所有股东提供合适的保护和平等权利的评估意见
		Element shareholder = cmpanyPublicInfo.findNextTag("table",governanceReview);
		reportNeeq.setEqualShareholderRightEvaluation(shareholder.text());
		//公司重大决策是否履行规定程序的评估意见
		Element procedure = cmpanyPublicInfo.findNextTag("table",shareholder);
		reportNeeq.setProcedureForMajorDecisionEvaluation(procedure.text());
		//公司章程的修改情况
		Element constitutionUpdateDtail= cmpanyPublicInfo.findNextTag("table",procedure);
		reportNeeq.setConstitutionUpdateDtail(constitutionUpdateDtail.text());
		//三会召开情况
		Element meetingDtail= cmpanyPublicInfo.findNextTag("table",constitutionUpdateDtail);
		Elements meetingDtailTd = meetingDtail.select("table tr > *");
		reportNeeq.setBoardMemberNo(meetingDtailTd.get(4).text());
		reportNeeq.setBoardMeetingReview(meetingDtailTd.get(5).text());
		reportNeeq.setSupervisorMeetingNo(meetingDtailTd.get(7).text());
		reportNeeq.setHasNewGovernancePolicy(meetingDtailTd.get(8).text());
		reportNeeq.setShareholdersMeetingNo(meetingDtailTd.get(10).text());
		reportNeeq.setShareholderMeetingReview(meetingDtailTd.get(11).text());
		//三会的召集、召开、表决程序是否符合法律法规要求的评估意见
		Element meetingProcedure= cmpanyPublicInfo.findNextTag("table",meetingDtail);
		reportNeeq.setMeetingProcedureLegitReview(meetingProcedure.text());
		//公司治理改进情况
		Element governanceImprovement= cmpanyPublicInfo.findNextTag("table",meetingProcedure);
		reportNeeq.setGovernanceImprovementReview(governanceImprovement.text());
		//投资者关系管理情况
		Element governancePolicy= cmpanyPublicInfo.findNextTag("table",governanceImprovement);
		reportNeeq.setHasNewGovernancePolicy(governancePolicy.text());
		//董事会下设专门委员会在本年度内履行职责时所提出的重要意见和建议(选填)
		Element investorRelationship = governancePolicy;
		if(!governancePolicy.nextElementSibling().tagName().equals("h2")){
			investorRelationship= cmpanyPublicInfo.findNextTag("table",governancePolicy);
			reportNeeq.setInvestorRelationshipMgtReview(investorRelationship.text());
		}
		//监事会就年度内监督事项的意见
		Element supervisorSugg= cmpanyPublicInfo.findNextTag("table",investorRelationship);
		reportNeeq.setSupervisorSugg(supervisorSugg.text());
		//公司保持独立性、自主经营能力的说明
		Element independence= cmpanyPublicInfo.findNextTag("table",supervisorSugg);
		reportNeeq.setCompanyIndependenceReview(independence.text());
		//对重大内部管理制度的评价
		Element managementPolicy= cmpanyPublicInfo.findNextTag("table",independence);
		reportNeeq.setMajorManagementPolicyReview(managementPolicy.text());
		//年度报告差错责任追究制度相关情况
		Element policyAgainst= cmpanyPublicInfo.findNextTag("table",managementPolicy);
		reportNeeq.setPolicyAgainstMajorReportErrorReview(policyAgainst.text());
		//第十节 财务报告
		//一、审计报告
		Element audited= cmpanyPublicInfo.findNextTag("table",policyAgainst);
		Elements auditedTd = audited.select("table tr > *");
		reportNeeq.setIsAudited(auditedTd.get(1).text());
		reportNeeq.setAuditOpinion(auditedTd.get(3).text());
		reportNeeq.setAuditReportSn(auditedTd.get(5).text());
		reportNeeq.setAuditFirm(auditedTd.get(7).text());
		reportNeeq.setAuditFirmAddress(auditedTd.get(9).text());
		reportNeeq.setAuditReportDate(auditedTd.get(11).text());
		reportNeeq.setCpaNames(auditedTd.get(13).text());
		reportNeeq.setIsAuditFirmChanged(auditedTd.get(15).text());
		reportNeeq.setAuditFirmSuccessiveServiceYear(auditedTd.get(17).text());
		String auditReport ="";
		for (int i = 18; i < auditedTd.size(); i++) {
			auditReport += auditedTd.get(i).text();
		}
		reportNeeq.setAuditReport(auditReport);
		reportNeeqRepositoy.save(reportNeeq);
//		return reportNeeq;
	}

}
